package com.wsm.kotlintest.common.net

import android.util.Log
import com.wsm.kotlintest.model.response.BaseResponseModel
import io.reactivex.Observer
import io.reactivex.disposables.Disposable

/**
 * Created by 王家宝 on 2018/7/19.
 * TEL:18241150668
 * MAIL:639586819@qq.com
 */
abstract class BaseObserver<T> : Observer<BaseResponseModel<T>> {
    companion object {
        const val TAG = "GlobalTag"
    }

    override fun onComplete() {
        onHandleComplete()
    }

    override fun onSubscribe(d: Disposable) {
    }

    override fun onNext(t: BaseResponseModel<T>) {
        if (t.data != null) onHandleSuccess(t.data) else onHandleError()
    }

    override fun onError(e: Throwable) {
        e.message?.let { Log.i(TAG, it) }
        onHandleError()
    }

    abstract fun onHandleError()
    abstract fun onHandleComplete()
    abstract fun onHandleSuccess(data: T)
}